home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Games / flying-6.11 / ball.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-30  |  3.8 KB  |  131 lines

  1. #ifndef _ball_h
  2. #define _ball_h
  3.  
  4. //
  5. // In dem Modul 'ball.h' sind alle Klassen vereint, die mit BΣllen und B÷gen
  6. // zu tun haben. Dabei gelten die folgenden Ableitungen
  7. //
  8. //               StaticArc            : GrundfunktionalitΣt
  9. //         /         \
  10. //         OuterArc     InnerArc    : Bogen, der von au▀en/innen reflektiert
  11. //        |       \   |
  12. //            |       ArcWall         : beidseitig reflektierend (Ableitung nur symbolisch)
  13. //        StaticBall                    : 360 Grad Bogen, nicht beweglich
  14. //        |
  15. //          Ball                        : Kugel (gleichzeitig ein DynObj)
  16. //
  17. //
  18. // Eine Besonderheit stellt der Ball dar, welcher die FunktionalitΣt des
  19. // DynObj und des Object besitzt. Au▀erdem ist er ein Beispiel, wie durch
  20. // spezielle Ausnutzung der HitFromBall-Routine die Kontrolle an ein Objekt
  21. // gebracht werden kann. Um Schrittweise die Geschwindigkeit durch Reibung
  22. // zu verringern, gibt er in der HitFromBall-Routine die Zeit des nΣchsten
  23. // Verlangsamungsschrittes zurⁿck, wenn er nach einer Kollision mit sich
  24. // selbst befragt wird.
  25. //
  26.  
  27. #ifndef _arcs_h
  28. #    include "arcs.h"            // Oberklasse StaticBall
  29. #endif
  30. #ifndef _dynobj_h
  31. #    include "dynobj.h"        // zweite Oberklasse DynObj
  32. #endif
  33.  
  34. class BallStateTop;        // forward
  35.  
  36. //
  37. // -------------------------------------------------------------------------
  38. //   class Ball:  Fliegende Kugeln
  39. // -------------------------------------------------------------------------
  40. //
  41.  
  42. class Ball : public StaticBall, public DynObj {
  43.     public:        // private
  44.         Vec2        v;                // Geschwindigkeits-Vektor
  45.         char            run_flag;    // Geschwingkeit ungleich null
  46.         const Real    a;                // Absolutwert der Negativ-Beschleunigung
  47. #if (SIM_SLOW)
  48.         Real            next_slowstep;        // Zeitpunkt der nΣchsten Verlangsamung
  49.         Real            last_slowstep;        // Zeitpunkt der letzten Verlangsamung
  50.         Real            slow_granoff;        // Offset bei Start, damit Kugeln zu
  51.                                                 // unterschiedlicher Zeit gebremst werden.
  52.         void            SlowStep();            // Kugel verlangsamen
  53. #endif
  54.  
  55.         class PBallTop    *pball;                // PBall, welcher den Lock hat
  56.         int    Lock( class PBallTop *pball );
  57.         int    Unlock( class PBallTop *pball );
  58.         void    GoUnlocked();
  59.  
  60.         BallStateTop    *state;
  61.         void SetState( BallStateTop *state_in )    { state = state_in; }
  62.  
  63.     public:        // protected
  64.         Real            m;            // Masse, wird vom RemotePBall veraendert !!!
  65.  
  66. #if (TIME_CACHE)
  67.         virtual void CollisionCalc();
  68.         virtual void HitYouAt( Object *obj, Real time );
  69.  
  70.         Object    *collision_object;
  71.         Real        collision_time;
  72. #endif
  73.  
  74.     public:
  75.         Ball( double x, double y, double vx, double vy, double r, double m );
  76.         Ball( double x, double y, double vx, double vy, double r );
  77.         Ball( double x, double y, double vx, double vy );
  78.         Ball( const Vec2 &v, double r, double m );
  79.         ~Ball();
  80.  
  81.         const Vec2 &V() const            { return v; }
  82.         const Real   &VX() const        { return v.X(); }
  83.         const Real   &VY() const        { return v.Y(); }
  84. //        Real   VXpix() const                { return v.Xpix(); }
  85. //        Real   VYpix() const                { return v.Ypix(); }
  86.         const    Real   &M() const            { return m; }
  87.  
  88.         int IsRunning() const            { return run_flag; }
  89.  
  90.         Vec2 Dir() const;
  91.         Real Len() const                    { return V().Norm(); }
  92.  
  93.         void SetP( const Vec2 &new_p );    // Kugel auf Position setzen (mit Zeichnen)
  94.         void SetV( const Vec2 &v_in );
  95.         void ChgV( const Vec2 &v_in ) {
  96.             SetV( v_in );
  97. #if (TIME_CACHE)
  98.             CollisionCalc();
  99. #endif
  100.         }
  101.  
  102.         void TellPressed();
  103.  
  104.         Real HitFromBall( Ball *b );
  105.         virtual Real NextCollision();
  106.         void CollideWithBall( Ball *b );
  107.  
  108.         static Real FindClosest( const Ball *myself,  const Vec2 &pos, Ball **best );
  109.         int FitsAt(const Vec2 &pos);
  110.         int FitsNextTo(const Vec2 &pos, const Vec2 &delta, Vec2 *newpos);
  111.  
  112.         virtual void Move( Real t );
  113.         virtual void Reset();
  114.         virtual void Redraw();
  115.  
  116.         virtual void Info();
  117.         virtual void WasHit(Object *);
  118.  
  119.         const BallStateTop *GetState()                    { return state; }
  120.  
  121.         void Draw();
  122.  
  123. friend class PBallTop;
  124. friend class LineKeeper;
  125. friend class StackKeeper;
  126. friend class Goal;
  127. };
  128.  
  129.  
  130. #endif
  131.